<?php

namespace SinoPHP\BbdBoss\Api;

use InvalidArgumentException;
use Symfony\Component\Console\Exception\InvalidOptionException;

use Upfor\UpforPHP\Library\Curl\Curl;
use Upfor\UpforPHP\Library\Math;

/**
 * IP变更
 *
 * Todo: 本接口尚未实现业务, 暂仅作为对外调试连通性
 *
 * Params:
 *      data:id         (integer)      IP对应ID
 *      data:oldIp      (string)       原IP
 *      data:newIp      (string)       新IP
 */
class GetCustomerDomain extends ApiAbstract {

    public function v_1_0_0() {
        $params = $this->requestParams;

        $this->checkToken(); // 校验TOKEN

        if (empty($params['startTime']) || empty($params['endTime'])) {
            throw new InvalidArgumentException('', 104001);
        }
        if (!is_numeric($params['startTime']) || !is_numeric($params['endTime'])) {
            throw new InvalidOptionException('', 104002);
        }
        if ($params['startTime'] > $params['endTime']) {
            throw new InvalidOptionException('',104004);
        }

        $url = config('bossUrl', 'outApi');
        $curl = new Curl();
        $curl->setTimeout(10);
        $curl->post($url.'/outApi/getCustomerDomain', $params);
        if($curl->error){
            throw new InvalidOptionException('',104003);
        }
        $curl->close();
        $data = json_decode($curl->rawResponse,true);

        // Todo
        // 如果参数[id]与[oldIp]不匹配, 报错

        // 业务逻辑实现

        // 成功, 返回success; 失败, 返回状态码+错误提示
        $this->success($data['data']);
    }

}
